mirror your GitHub repos to tangled.org automatically
1

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.1 kB View raw
1import { and, eq } from 'drizzle-orm' 2import { repoMapping } from '#server/db/schema' 3import { useDb } from '#server/utils/db' 4import { enqueue } from '#server/utils/queue' 5import { requireSessionAndMappingId } from '#server/utils/repo-route' 6 7/** 8 * Enqueue a forced `tangled.create-repo` job for one mapping. The handler 9 * normally no-ops when a mapping already exists; the `force: true` envelope 10 * flag tells it to re-run the enrolment flow. 11 */ 12export default defineEventHandler(async event => { 13 const { session, mappingId } = await requireSessionAndMappingId(event) 14 15 const db = useDb() 16 const rows = await db.select({ 17 githubRepoId: repoMapping.githubRepoId, 18 }) 19 .from(repoMapping) 20 .where(and( 21 eq(repoMapping.id, mappingId), 22 eq(repoMapping.installationId, session.installationId), 23 )) 24 .limit(1) 25 if (rows.length === 0) { 26 throw createError({ statusCode: 404, statusMessage: 'mapping not found' }) 27 } 28 29 const row = await enqueue('tangled.create-repo', { 30 installationId: session.installationId, 31 githubRepoId: rows[0]!.githubRepoId, 32 force: true, 33 }) 34 return { jobId: row?.id ?? null } 35})